﻿using System;
using System.Collections.Generic;
using Alex.Library.Specifications;

namespace Alex.Framework.Domain.Repositories
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="T">聚合根类型</typeparam>
    public interface IRepository<T> where T: IAggregateRoot
    {
        /// <summary>
        /// 获取仓储上下文
        /// </summary>
        IRepositoryContext Context { get; }

        /// <summary>
        /// 通过聚合根唯一标识获取聚合根实体
        /// </summary>
        /// <param name="rootId">聚合根唯一标识</param>
        /// <returns>聚合根实体</returns>
        T GetByRootID(string rootId);

        /// <summary>
        /// 根据条件查询聚合根实体集合
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns>聚合根实体集合</returns>
        IEnumerable<T> FindAll(ISpecification<T> specification);

        /// <summary>
        /// 根据条件查询聚合根实体
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns>聚合根实体</returns>
        T Find(ISpecification<T> specification);

        /// <summary>
        /// 判断聚合根实体是否存在与仓储中
        /// </summary>
        /// <param name="specification">查询条件</param>
        /// <returns></returns>
        bool Exists(ISpecification<T> specification);

        /// <summary>
        /// 向仓储中添加聚合根实体
        /// </summary>
        /// <param name="root">聚合根实体</param>
        void Add(T root);

        /// <summary>
        /// 修改仓储中的聚合根实体信息
        /// </summary>
        /// <param name="root">新的聚合根实体</param>
        void Update(T root);

        /// <summary>
        /// 删除仓储中的聚合根实体
        /// </summary>
        /// <param name="root">待删除的聚合根实体</param>
        void Remove(T root);
    }
}
